//
//  ViewController.swift
//  XMenSwift
//
//  Created by X-MEN on 2021/12/13.
//

import UIKit

class tempModel {
    
    var name :String?
}

class ViewController: UIViewController,UICollectionViewDataSource {
    
    
    var model : tempModel? {
        didSet {
            model?.name = "哈哈哈"
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //数组中的字典
        var dictArray  =  [[String : String]]()
        dictArray.append(["name" : "zhangshan"])
        print(dictArray)


        let array : [String] = ["","88","123","456","789",]
        //带下标的循环
        for (index,value) in array.enumerated() {
            print(index,value)
        }
        
        //筛选
        let tempArray = array.filter { str in
            str == "123"
        }
        print(tempArray)
        
        let tempArray2 : [Int] = array.map { str in
            Int(str) ?? 0
        }
        print(tempArray2)

        let numArray = [1,20,30,0.6,15]

        //排序
        let tempNumArray = numArray.sorted { value1, value2 in
            value1 < value2
        }
        print(tempNumArray)
        
        
        /*--------字典操作----------*/
        
        let dict : [String : String] = ["qq" : "11222","key" : "12"]
        var parameters = [String: Any]()
        for (key,value) in dict {
            parameters[key] = value;
        }
        print("parameters", parameters)
        let string : String = parameters["qq"] as? String ?? ""
        print(String(format: "hahhaha %@",string))
        print(String(format: "NNNNN%@ ll %.1f", arguments: ["CVarArg",999.99]))

    

    }
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 1
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        return UICollectionViewCell()
    }
    
    @IBAction func blockEvent(_ sender: Any) {
        let vc = BlockWithAsyncAwaitViewController()
        vc.didSelItemBlock = {[weak self] (model,str) in
            
        }
        self.present(vc, animated:true, completion: nil)
    }
    
}

extension ViewController {
    //逃逸B包加 [weak self]
    //    self.dispatcher.scanForPeripherals(withServices: nil, options: nil) { [weak self] (peripheral, advertisementData, RSSI) in
    //        if let printer = peripheral, let uuids = self?.allPrinters.map({ $0.identifier.uuidString }) {
    //
    //        }
    //
    //    }
    
    
}

